/**
 * @desc 实时获取当前时间
 * @return{string}
 * */

const padDate = function (value) {
    return value < 10 ? '0' + value : value;
};
export const getDate = () => {
    const date = new Date(),
        year = date.getFullYear(),
        month = padDate(date.getMonth() + 1),
        day = padDate(date.getDate()),
        hours = padDate(date.getHours()),
        minutes = padDate(date.getMinutes()),
        seconds = padDate(date.getSeconds()),
        week = date.getDay();
    const WEEK_ARR = ["日", "一", "二", "三", "四", "五", "六"];
    return `${year}-${month}-${day} 星期${WEEK_ARR[week]} ${hours}:${minutes}:${seconds}`;
};


export const getDateTime = () => {
    const date = new Date(),
        year = date.getFullYear(),
        month = padDate(date.getMonth() + 1),
        day = padDate(date.getDate())
    //return year+'-'+month+'-'+day+' '+ hours +':'+minutes+':'+seconds;
    return year + '-' + month + '-' + day;
};
export const getDateTime3 = (d) => {
    const date = new Date(d),
        year = date.getFullYear(),
        month = padDate(date.getMonth() + 1),
        day = padDate(date.getDate())
    //return year+'-'+month+'-'+day+' '+ hours +':'+minutes+':'+seconds;
    return year + '-' + month + '-' + day;
};
export const getDateTime2 = (d, type) => {
    const date = new Date(d),
        year = date.getFullYear(),
        month = padDate(date.getMonth() + 1),
        day = padDate(date.getDate()),
        hours = padDate(date.getHours()),
        minutes = padDate(date.getMinutes()),
        seconds = padDate(date.getSeconds());
    if (type === 'date') {
        return year + '-' + month + '-' + day;
    } else {
        return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    }
};
export const getTimeHm = (d) => {
    const date = new Date(d),
        hours = padDate(date.getHours()),
        minutes = padDate(date.getMinutes())
    
    return hours + ':' + minutes;
    
};
export const getDay = (day) => {

    var today = new Date();

    var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;

    today.setTime(targetday_milliseconds); //注意，这行是关键代码

    var tYear = today.getFullYear();

    var tMonth = today.getMonth();

    var tDate = today.getDate();

    tMonth = doHandleMonth(tMonth + 1);

    tDate = doHandleMonth(tDate);

    return tYear + "-" + tMonth + "-" + tDate;

}

function doHandleMonth(month) {

    var m = month;

    if (month.toString().length === 1) {

        m = "0" + month;

    }

    return m;

}
